/*****************************************************************************
 *   Copyright 2005 Tim A Wang
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 ****************************************************************************/
package com.jb.web.bean;

import com.jb.framework.PersistentContext;
import com.jb.web.bean.inspector.BackgroundPropertyEditor;



public class MenuItem extends JBTreeNode {
    static final long serialVersionUID = 123123L;

    static {
        publish(MenuItem.class, STYLE, "hoverStyle", new BackgroundPropertyEditor());
        publish(MenuItem.class, GENERAL, "childBoxStyle", new BackgroundPropertyEditor());
        publish(MenuItem.class, GENERAL, "destination");
    }

    String childBoxStyle; //border style of children menus
    private String hoverStyle;

    /**
     * DOCUMENT ME!
     *
     * @param component DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public boolean isChildAccepatble(BaseComponent component) {
        return com.jb.web.bean.MenuItem.class.isInstance(component);
    }

    /**
     * DOCUMENT ME!
     *
     * @param pChildBoxStyle DOCUMENT ME!
     */
    public void setChildBoxStyle(String pChildBoxStyle) {
        childBoxStyle = pChildBoxStyle;
    }
    public String getChildBoxStyle() {
        if (childBoxStyle != null) {
            return childBoxStyle;
        }

        if (getParent() instanceof MenuItem) {
            return ((MenuItem) getParent()).getChildBoxStyle();
        }

        return "";
    }

    public void setDefault(PersistentContext pContext) {
        super.setDefault(pContext);
        this.setValue("Menu Item");

        if (this.getParent() instanceof MenuItem) {
            this.hoverStyle = ((MenuItem) getParent()).getHoverStyle();
        } else {
            this.hoverStyle = "background-color:highlight; color:white;";
        }

        this.setStyleClass("jbMenuItem");
    }

    public String getFontStyle() {
        if ((super.getFontStyle() == null) && (getParentNode() != null)) {
            return getParentNode().getFontStyle();
        } else {
            return super.getFontStyle();
        }
    }

    public void setHoverStyle(String hoverStyle) {
        this.hoverStyle = hoverStyle;
    }
    public String getHoverStyle() {
        return hoverStyle;
    }
}
